package com.cy.response;


import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * 统一响应结果类型
 *
 * @author java@tedu.cn
 * @version 0.0.1
 */
@Data
public class JsonResult<T> implements Serializable {


    @ApiModelProperty("业务状态码")
    private Integer state;

    @ApiModelProperty("提示文本")
    private String message;

    @ApiModelProperty("数据")
    private T data;

    public static JsonResult<Void> ok() {
        return ok(null);
    }

    public static <T> JsonResult<T> ok(T data) {
        JsonResult<T> jsonResult = new JsonResult<>();
        jsonResult.state = ServiceCode.OK.getValue();
        jsonResult.data = data;
        return jsonResult;
    }

    public static JsonResult<Void> fail(String message) {
        JsonResult<Void> jsonResult = new JsonResult<>();
        jsonResult.message = message;
        return jsonResult;
    }


}